package com.sub.lambda;

import java.util.Optional;
import java.util.function.Consumer;

/**
 * @ClassName LambdaTest
 * @Description: TODO
 * @Author Submerge.
 * @Since 2023/8/30 17:27
 * @Version 1.0
 */
public class LambdaDemo1 {

    public static void main(String[] args) {
        /**
         * 练习描述
         * String s = "林青霞,30";
         * 请按照我指定的要求进行操作：
         * 1:将字符串截取得到数字年龄部分
         * 2:将上一步的年龄字符串转换成为int类型的数据
         * 3:将上一步的int数据加70，得到一个int结果，在控制台输出
         * 请通过Function接口来实现函数拼接
         */


        Fly fly = new Fly() {
            @Override
            public void fly() {
                System.out.println("i can fly");
            }
        };
        fly.fly();

        Fly fly2 = () -> System.out.println("i can't fly");
        fly2.fly();

        String[] strArray = {"林青霞,30", "张曼玉,35", "王祖贤,33"};

        Consumer<String> consumer = new Consumer<String>() {
            @Override
            public void accept(String s) {
                String[] split = s.split(",");
                System.out.println(split[0] + ":" + split[1]);
            }
        };

        for (String s : strArray) {
            consumer.accept(s);
        }

        Consumer<String> consumer1 = (s) -> {
            String[] split = s.split(",");
            System.out.println(split[0] + ":" + split[1]);
        };
        for (String s : strArray) {
            consumer1.accept(s);
        }

    }
}
